home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / ENCRYPT.SWG / 0016_An Encoder for passwords.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  2KB  |  72 lines

  1. {
  2. KEITH TYSINGER
  3.  
  4. You can make an encoder that will scramble a string(s) that even YOU, the
  5.  programmer couldn't unscramble without a password. They are many different
  6.  ways to scramble a string; just be creative! One way is to swap every
  7.  character with another character ( ex. swap every letter 'A' with the number
  8.  '1') , a better way would use a password to scramble it. Here is a simple
  9.  procedure that requires the password, the string to be scrammbled, and returns
  10.  the scrambled string. The password should not exceed 20 characters in length.
  11. Forget about the messy code; I blame my word processor:
  12. }
  13.  
  14. procedure encode(password, instring : string; var outstring : string);
  15. var
  16.   len,
  17.   pcounter,
  18.   scounter : byte;
  19.  
  20. begin
  21.   len := length(password) div 2;
  22.   scounter := 1;
  23.   pcounter := 1;
  24.  
  25.   repeat
  26.     outstring := outstring + chr(ord(password[pcounter]) +
  27.                              ord(instring[scounter]) + len);
  28.     inc(scounter);
  29.     inc(pcounter);
  30.     if pcounter > length(password) then
  31.       pcounter := 1;
  32.   until scounter > length(instring);
  33. end;
  34.  
  35. procedure decode(password, instring : string; var outstring : string);
  36. var
  37.   len,
  38.   pcounter,
  39.   scounter : byte;
  40.  
  41. begin
  42.   len := length(password) div 2;
  43.   scounter := 1;
  44.   pcounter := 1;
  45.  
  46.   repeat
  47.     outstring := outstring + chr(ord(instring[scounter]) -
  48.                              ord(password[pcounter]) - len);
  49.     inc(scounter);
  50.     inc(pcounter);
  51.     if pcounter > length(password) then
  52.       pcounter := 1;
  53.   until scounter > length(instring);
  54. end;
  55.  
  56. var
  57.   password,
  58.   original,
  59.   scrambled,
  60.   descrambled : string;
  61. begin
  62.   original := 'Hello There!';
  63.   password := 'Eat my';
  64.   encode(password, original, scrambled);
  65.   writeln('orig = ', original);
  66.   writeln('scrm = ', scrambled);
  67.   decode(password, scrambled, descrambled);
  68.   writeln('dcod = ', descrambled);
  69.   readln;
  70. end.
  71.  
  72.